package com.highper.application.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.highper.application.service.IAppUserService;
import com.highper.application.service.remote.IAdminRemoteService;
import com.highper.common.entity.po.application.AppUser;
import com.highper.common.entity.response.HighperResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author ZhangGJ
 * @Date 2022/01/27 16:27
 */
@RestController
@RequestMapping("app/user")
public class AppUserController {

    private final IAppUserService appUserService;
    private final IAdminRemoteService adminRemoteService;

    @Autowired
    public AppUserController(IAppUserService appUserService,
            IAdminRemoteService adminRemoteService) {
        this.appUserService = appUserService;
        this.adminRemoteService = adminRemoteService;
    }

    @GetMapping("list")
    public HighperResponse appUserList() {
        AppUser appuser = (AppUser) StpUtil.getSession().get("user");
        return HighperResponse.data(appUserService.list());
    }

    @GetMapping("admin/user")
    public HighperResponse adminUser() {
        return HighperResponse.data(adminRemoteService.adminUserList());
    }

    @GetMapping("info")
    public HighperResponse appUserInfo(@RequestParam Long userId) {
        return HighperResponse.data(appUserService.appUserInfo(userId));
    }
}
